package com.moleq.adapter;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.moleq.models.Users;
import com.moleq.mgpos.activities.R;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;



public class UserListAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<Users>listItem;
	private int selectedRow = 0;
	private String ls;
	public UserListAdapter(Context context,List<Users> listItem){
		this.mInflater = LayoutInflater.from(context);
		this.listItem = listItem;
	}
	
	public void setSource(List<Users> listItem){
		this.listItem = listItem;
	}
	
	public int getCount() {
		// TODO Auto-generated method stub
		return listItem.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listItem.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		// TODO Auto-generated method stub
				ViewHolder holder = null;
				if(convertView == null){
					holder = new ViewHolder();
					convertView = mInflater.inflate(R.layout.user_list_item, null);
					holder.us_info = (TextView) convertView.findViewById(R.id.tv_user_name);
					convertView.setTag(holder);
				}else{
					holder = (ViewHolder) convertView.getTag();
				}
				
				holder.us_info.setTextSize(16);
				
				holder.us_info.setText(String.valueOf(listItem.get(position).getUs_login_id()) +"   "+String.valueOf(listItem.get(position).getUs_info()));
				
				if (position == selectedRow) {
					holder.us_info.setBackgroundColor(Color.rgb(255,219,16));

				} else {
					holder.us_info.setBackgroundColor(Color.rgb(204, 204, 204));
				}
				
				return convertView;
	}
	
	public final class ViewHolder{
		public TextView us_info ;

	}
	public void ScrollToRow(int row) {
		selectedRow = row;
		this.notifyDataSetChanged();
	}
	public int GetSelectedIndex(){
		return selectedRow;
	}

};
